namespace EyeOpen.SampleCms.Web.UI.Controls
{
    using System;
    using System.Web;
    using System.Web.UI.WebControls;

    public partial class Menu : BaseUserControl
    {
        protected override void OnLoad(EventArgs e)
        {
            var nodes = new SiteMapNodeCollection(SiteMap.RootNode.ChildNodes);
            nodes.Insert(0, SiteMap.RootNode);
            rptMenu.DataSource = nodes;
            rptMenu.DataBind();
        }

        protected void RepeaterMenuItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if ((e.Item.ItemType != ListItemType.Item) && (e.Item.ItemType != ListItemType.AlternatingItem))
            {
                return;
            }

            if (SiteMap.CurrentNode == null)
            {
                return;
            }

            var currentNode = (SiteMapNode)e.Item.DataItem;

            if (!SiteMap.CurrentNode.Equals(currentNode))
            {
                return;
            }

            var hypSection = (HyperLink)e.Item.FindControl("hypSection");

            hypSection.CssClass = "currentSection";
            hypSection.NavigateUrl = string.Empty;
        }
    }
}